package com.example.supernote.ui.note.components

import androidx.compose.material3.Slider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.stringResource
import com.example.supernote.R
import com.example.supernote.ui.components.UniformDialog
import com.example.supernote.ui.components.UniformPreviewBody

@Composable
fun ShowSizePicker(
    onCancel: () -> Unit,
    onConfirm: (String) -> Unit
) {
    var fontSize by remember { mutableFloatStateOf(3f) }

    // 将字体大小转换为适合 Slider 使用的值
    val fontSizeRange = 1f..7f // 字体大小范围

    UniformDialog(
        title = stringResource(R.string.note_font_size),
        onCancel = onCancel,
        onConfirm = { onConfirm(fontSize.toInt().toString()) },
        body = {
            UniformPreviewBody(
                title = stringResource(R.string.note_example_preview),
                html = "<div style='margin: 10px 0'><font size='$fontSize'>${stringResource(R.string.note_example_text)}</font></div>"
            )
            Slider(
                value = fontSize,
                onValueChange = { fontSize = it },
                valueRange = fontSizeRange
            )
        }
    )
}